import numpy
import pylab
import sys


def get_input_matrix(fname):
    input = []
    input_matrix = []
    file = open(fname, "r")
    for line in file:
        if "EOD" in line:
            input_matrix.append(input)
            input = []
        else:
            input.append(int(line))
    return input_matrix


def get_input(fname):
    input = []
    file = open(fname, "r")
    for line in file:
        input.append(int(line))
    return input


def main():
    if len(sys.argv) != 3:
        print "Usage: %s START END" % sys.argv[0]
        sys.exit(-1)
    startx = int(sys.argv[1])
    endx = int(sys.argv[2])
    x = get_input("plaudex.out")
    pylab.subplot(311)
    pylab.plot(x)
    pylab.subplot(312)
    pylab.plot(x[startx:endx])
    pylab.subplot(313)
    pylab.plot(abs(numpy.fft.fft(x[startx:endx], 1024)))
    pylab.show()


if __name__ == "__main__":
    #main()
    if len(sys.argv) != 2:
        print "Usage: %s MATRIX_INDEX" % sys.argv[0]
        sys.exit(-1)
    matrix_index = int(sys.argv[1])
    xmatrix = get_input_matrix("plaudex_window.out")
    x = xmatrix[matrix_index]
    pylab.plot(x)
    pylab.show()
    